//
//  STNewFeatureController.m
//  OCVVeibo
//
//  Created by leergou on 16/7/23.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STNewFeatureController.h"
#import "STNewFeatureCell.h"

static NSString *newFeatureCell = @"newFeatureCell";

@interface STNewFeatureController ()

@property (nonatomic,strong) UIImageView *imageView;

@property (nonatomic,strong) UIButton *experienceButton;

@property (nonatomic,assign) NSInteger index;

@end

@implementation STNewFeatureController


#pragma mark - 重写 init 方法,指定布局
- (instancetype)init{
    
        // 创建布局对象
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        
        // 此时 view 没有 frame,不能参照 view 设置,或者也可以在 viewDidLayoutSubViews 中完成设置
        layout.itemSize = [UIScreen mainScreen].bounds.size;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
    
    return [super initWithCollectionViewLayout:layout];
}



#pragma mark - viewDidLoad
- (void)viewDidLoad{
    [super viewDidLoad];
    // setupUI
    [self setupUI];
}
#pragma mark - collectionView delegate


#pragma mark - collectionView dataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    STNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:newFeatureCell forIndexPath:indexPath];
    
    cell.index = indexPath.row;
    
    if (indexPath.row == 3) {
        [self startAnimation:cell.experienceButton];
    }
    return cell;
}

- (void)startAnimation:(UIButton *)button{
    button.hidden = NO;
    button.transform = CGAffineTransformMakeScale(0, 0);
    button.userInteractionEnabled = NO;
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        
        button.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        
        button.userInteractionEnabled = YES;
        
    }];
}



#pragma mark - setupUI
- (void)setupUI{
    
    //MAKR: 设置collectionView 属性
    self.collectionView.bounces = NO;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    
    // MARK: 注册
    [self.collectionView registerClass:[STNewFeatureCell class] forCellWithReuseIdentifier:newFeatureCell];
}





@end








